package com.ruoyi.employer.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.employer.domain.CargoSourceDetails;
import com.ruoyi.employer.service.ICargoSourceDetailsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 货源详情Controller
 * 
 * @author adf
 * @date 2024-08-14
 */
@RestController
@RequestMapping("/employer/sourcedetails")
public class CargoSourceDetailsController extends BaseController
{
    @Autowired
    private ICargoSourceDetailsService cargoSourceDetailsService;

    /**
     * 查询货源详情列表
     */
    @PreAuthorize("@ss.hasPermi('employer:sourcedetails:list')")
    @GetMapping("/list")
    public TableDataInfo list(CargoSourceDetails cargoSourceDetails)
    {
        System.out.println("nihaonihao");
        startPage();
        List<CargoSourceDetails> list = cargoSourceDetailsService.selectCargoSourceDetailsList(cargoSourceDetails);
        return getDataTable(list);
    }

    /**
     * 导出货源详情列表
     */
    @PreAuthorize("@ss.hasPermi('employer:sourcedetails:export')")
    @Log(title = "货源详情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CargoSourceDetails cargoSourceDetails)
    {
        List<CargoSourceDetails> list = cargoSourceDetailsService.selectCargoSourceDetailsList(cargoSourceDetails);
        ExcelUtil<CargoSourceDetails> util = new ExcelUtil<CargoSourceDetails>(CargoSourceDetails.class);
        util.exportExcel(response, list, "货源详情数据");
    }

    /**
     * 获取货源详情详细信息(根据货源ID)
     */
    @PreAuthorize("@ss.hasPermi('employer:sourcedetails:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(cargoSourceDetailsService.selectCargoSourceDetailsById(id));
    }

    /**
     * 获取货源详情详细信息(根据货主ID)
     */
    @PreAuthorize("@ss.hasPermi('employer:sourcedetails:query')")
    @GetMapping(value = "/getInfoByCargoId/{id}")
    public AjaxResult getInfoByCargoId(@PathVariable("id") Long id)
    {
        return success(cargoSourceDetailsService.selectCargoSourceDetailsListByCargoUserId(id));
    }

    /**
     * 新增货源详情
     */
    @PreAuthorize("@ss.hasPermi('employer:sourcedetails:add')")
    @Log(title = "货源详情", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CargoSourceDetails cargoSourceDetails)
    {
        return toAjax(cargoSourceDetailsService.insertCargoSourceDetails(cargoSourceDetails));
    }

    /**
     * 修改货源详情
     */
    @PreAuthorize("@ss.hasPermi('employer:sourcedetails:edit')")
    @Log(title = "货源详情", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CargoSourceDetails cargoSourceDetails)
    {
        return toAjax(cargoSourceDetailsService.updateCargoSourceDetails(cargoSourceDetails));
    }

    /**
     * 删除货源详情
     */
    @PreAuthorize("@ss.hasPermi('employer:sourcedetails:remove')")
    @Log(title = "货源详情", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(cargoSourceDetailsService.deleteCargoSourceDetailsByIds(ids));
    }
}
